#!/usr/bin/env python
# coding=utf-8

import unittest
import time
from utility import app
from utility import base
from utility.type import *

class LoginTests(base.BaseTests):

    @classmethod
    
    def setUpClass(cls):
        cls.driver = app.start_app(True)

    def test_log1in(self,mobile='18210817745',password='123456'):


        time.sleep(5)
        login_btn = self.driver.find_element_by_ios_predicate(u'name MATCHES "登.*?录"')
        self.assertIsNotNone(login_btn, u'登录界面必须有 [登录] 按钮')
        login_btn.click()

        time.sleep(2)

        mobile_field = self.driver.find_element_by_class_name(ElementType.TextField)
        passwd_field = self.driver.find_element_by_class_name(ElementType.SecureTextField)

        self.assertIsNotNone(mobile_field, u'必须要有手机号输入框')
        self.assertIsNot(passwd_field, u'必须要有密码输入框')

        mobile_field.send_keys(mobile)
        passwd_field.send_keys(password)

        self.hide_keyboard()

        login_btn = self.driver.find_element_by_ios_predicate(u'name LIKE "登*录"')
        self.assertIsNotNone(login_btn, u'登录界面必须有 [登录] 按钮（输入账号页面）')
        login_btn.click()



if __name__ == '__main__':
    test_suite = unittest.TestLoader().loadTestsFromTestCase(LoginTests)
    unittest.TextTestRunner().run(test_suite)
